#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  first.py
#       Author @  Huoty
#  Create date @  2016-07-02 13:02:57
#  Description @  
# *************************************************************

class Descriptor(object):
    def __init__(self, m):
        self.m = m

    def __get__(self, instance, owner):
        return instance.n * self.m

    def __set__(self, instance, value):
        if value < 0:
            raise ValueError("Negative value not allowed: %s" % value)
        instance.n = value

    def __delete__(self, instance):
        pass

class Foo(object):
    __slots__ = ("n", )
    bar = Descriptor(0)
    har = Descriptor(1)
    tar = Descriptor(2)
    yar = Descriptor(3)

    def __init__(self, n):
        self.n = n

class Foo2(object):
    def __init__(self, n):
        self.n = n
        self.bar = Descriptor(3)



# Script starts from here
    
if __name__ == "__main__":
    obj = Foo(10)
    print obj.bar
    obj.bar = 200
    print obj.bar
    del obj.bar
    obj.c = 3

